package com.gosophia.conference.action.scheme;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.commons.web.logAnnotation.LogRecord;
import com.gosophia.conferenceManagement.ConferenceTurningAction;
import com.gosophia.conferenceManagement.common.dto.DocumentDTO;
import com.gosophia.conferenceManagement.common.ws.ConferenceHandleWebService;
import com.gosophia.conferenceManagement.scheme.dto.SchemeJobDataDTO;
import com.gosophia.conferenceManagement.scheme.ws.ConferenceSchemeWebService;
import com.gosophia.oa.action.JudgeCurrentUndertaker;
import com.gosophia.springsecurity.UserDetailsImpl;
import com.opensymphony.xwork2.ActionContext;

/**
 * 方案修改 -取回并提交/取回并直接定稿/定稿Action，此Action用于方案取回页面【提交】按钮和【定稿】按钮和方案定稿页面的【定稿】
 * @author nana
 *
 */
@SuppressWarnings("serial")
@Scope("prototype")
@Controller("SchemeModifyGetBackAndSubmitAction")
public class SchemeModifyGetBackAndSubmitAction extends BaseSupportAction{

private Long jobId;
    
    private String nextStep;
    
    private String onlinePath;
    
    private String onlineVersion;
    
    private SchemeJobDataDTO schemeJobDataDTO;
    
    @Autowired
    private ConferenceSchemeWebService conferenceSchemeWebService;
    @Autowired
    private JudgeCurrentUndertaker judgeCurrentUndertaker;
    
    @Override
    @LogRecord(eventAction="会议管理-取回方案",eventTarget="schemeJobDataDTO")
    public String _execute() throws Exception {
        
        //判断当前用户和job承办人是否匹配,如果不匹配转到异常页面
        judgeCurrentUndertaker.judgeOperationAuthority(jobId);
        
        UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder
        .getContext().getAuthentication().getPrincipal();
        Long userInfoId = userDetails.getUserAccountDTO().getUserInfoDTO().getUserInfoId();
        
        DocumentDTO doc = new DocumentDTO();
        doc.setDocumentPath(onlinePath);
        doc.setDocumentVersion(onlineVersion);
        doc.setDocumentCategory("online");
        schemeJobDataDTO.setOnlineDocumentDTO(doc);
        
        if("GETBACK_APPROVAL".equals(nextStep)){
            schemeJobDataDTO.setTurningAction(ConferenceTurningAction.GETBACK_APPROVAL.getValue());
        }else if("GETBACK_FINALIZED".equals(nextStep)){
            schemeJobDataDTO.setTurningAction(ConferenceTurningAction.GETBACK_FINALIZED.getValue());
        }else if("FINALIZE".equals(nextStep)){
            schemeJobDataDTO.setTurningAction(ConferenceTurningAction.FINALIZE.getValue());
        }
        conferenceSchemeWebService.HandleConferenceSchemeTurning(jobId, userInfoId, schemeJobDataDTO);
        
        super.getRequestResult().setRsltCode("0");
        super.getRequestResult().setMessage("会议取回成功");
        ActionContext.getContext().getSession().put("_lastOpResult", super.getRequestResult());
        if("task".equals(this.getFromFlag())){
            return "TASK";
        }
        return SUCCESS;
    }


    public void setJobId(Long jobId) {
        this.jobId = jobId;
    }

    public Long getJobId() {
        return jobId;
    }

    public String getNextStep() {
        return nextStep;
    }

    public void setNextStep(String nextStep) {
        this.nextStep = nextStep;
    }


    public SchemeJobDataDTO getSchemeJobDataDTO() {
        return schemeJobDataDTO;
    }


    public void setSchemeJobDataDTO(SchemeJobDataDTO schemeJobDataDTO) {
        this.schemeJobDataDTO = schemeJobDataDTO;
    }


    public String getOnlinePath() {
        return onlinePath;
    }


    public void setOnlinePath(String onlinePath) {
        this.onlinePath = onlinePath;
    }


    public String getOnlineVersion() {
        return onlineVersion;
    }


    public void setOnlineVersion(String onlineVersion) {
        this.onlineVersion = onlineVersion;
    }
}
